package com.web.index;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.web.base.BaseDAO;
import com.web.base.Page;

public class WapIndexAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String serType;
	private String serKey;
	private String cId;
	private BaseDAO baseDao;
	private List proList;
	private Page myPage;

	public String execute() {

		HttpServletRequest request = ServletActionContext.getRequest();

		// String _method = request.getMethod();
		String uri = request.getRequestURI();
		System.out.println("uri=" + uri);
		System.out.println("serType=" + serType);
		System.out.println("serKey=" + serKey);
		if (uri.startsWith("/city")) {
			return this.cityList();
		} else if (uri.startsWith("/search") && null != serType) {
			if ("0".equals(serType) && null != serKey && serKey.length() > 0) {
				return this.product();
			} else if ("1".equals(serType) && null != serKey
					&& serKey.length() > 0) {
				return this.merchant();
			} else if ("2".equals(serType) && null != serKey
					&& serKey.length() > 0) {
				return this.promotion();
			} else if ("3".equals(serType) && null != serKey
					&& serKey.length() > 0) {
				return this.mall();
			} else {
				return this.doSearch();
			}
		} else {
			return this.index();
		}
	}

	public String index() {
		String hql = " FROM ForsearchMallpromotion fmp";
		//proList = this.baseDao.findByHql(0, 10, hql);
		myPage = this.baseDao.findPage(hql, 1, 10);
		return SUCCESS;
	}

	/**
	 * city List
	 * 
	 * @return
	 */
	public String cityList() {
		return "city";
	}

	public String product() {

		return "product";
	}

	public String promotion() {

		return "promotion";
	}

	public String merchant() {

		return "merchant";
	}

	public String mall() {

		return "mall";
	}

	public String doSearch() {

		return "search";
	}

	public String getSerType() {
		return serType;
	}

	public void setSerType(String serType) {
		this.serType = serType;
	}

	public String getSerKey() {
		return serKey;
	}

	public void setSerKey(String serKey) {
		this.serKey = serKey;
	}

	public String getCId() {
		return cId;
	}

	public void setCId(String id) {
		cId = id;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public BaseDAO getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDAO baseDao) {
		this.baseDao = baseDao;
	}

	public List getProList() {
		return proList;
	}

	public void setProList(List proList) {
		this.proList = proList;
	}

	public Page getMyPage() {
		return myPage;
	}

	public void setMyPage(Page myPage) {
		this.myPage = myPage;
	}

}
